In [2]:
%pylab
In [3]:
%matplotlib inline
In [4]:
cd ..
In [5]:
import sys
import numpy as np
import skimage
import cv2
In [6]:
import neukrill_net.utils as utils
import neukrill_net.image_processing as image_processing
In [7]:
from IPython.display import display
from IPython.display import Image
from IPython.display import HTML
In [8]:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
In [71]:
#img = skimage.io.imread('data/train/acantharia_protist/100224.jpg')
img = skimage.io.imread('data/train/acantharia_protist/64.jpg')
Had to set the edgeThreshold parameter manually because default of 31 removes the entire image with small images!
In [125]:
detector = cv2.ORB_create(nfeatures=500, edgeThreshold=0, patchSize=31)
norm = cv2.NORM_HAMMING
In [77]:
# One step process
kp, des = detector.detectAndCompute(img, None)
In [51]:
# Two step process
# find the keypoints with ORB
kp = detector.detect(img, None)
# compute the descriptors with ORB
kp, des = detector.compute(img, kp)
In [78]:
# draw only keypoints location,not size and orientation
#img2 = cv2.drawKeypoints(img, kp, color=(0,255,0), flags=0)
img2 = img
img2 = cv2.drawKeypoints(img, kp, img2, flags=0)
imgplot = plt.imshow(img2)
imgplot.set_cmap('gray')
plt.show()
In [79]:
len(kp)
Out[79]:
In [129]:
des[0:3,:]
Out[129]:
In [127]:
type(des)
Out[127]:
One of the code examples uses equalizeHist as a preprocessing step. Do we want to do this?
In [80]:
imgplot = plt.imshow(cv2.equalizeHist(img))
imgplot.set_cmap('gray')
plt.show()
Clearly not, as the abundance of white pixels has set everything else to be black! Might need to find a different way of normalising the images.
In [81]:
import neukrill_net.utils as utils
import neukrill_net.image_processing as image_processing
In [82]:
settings = utils.Settings('settings.json')
In [86]:
# Load the height and width of training data
X, names = utils.load_data(settings.image_fnames, processing=image_processing.attributes_wrapper(['width','height']), classes=settings.classes)
In [116]:
fullnames = [myname for classname in settings.classes for myname in settings.image_fnames['train'][classname]]
In [117]:
indexMinWidth = numpy.argmin(X[:,0])
indexMinHeight = numpy.argmin(X[:,1])
indexMinPixels = numpy.argmin(np.prod(X,axis=1))
indexMaxWidth = numpy.argmax(X[:,0])
indexMaxHeight = numpy.argmax(X[:,1])
indexMaxPixels = numpy.argmax(np.prod(X,axis=1))
In [118]:
indexList = [indexMinWidth, indexMinHeight, indexMinPixels, indexMaxWidth, indexMaxHeight, indexMaxPixels]
In [119]:
imgList = [skimage.io.imread(fullnames[index]) for index in indexList]
In [120]:
for img in imgList:
print(img.shape)
In [126]:
for i,img in enumerate(imgList):
imgplot = plt.imshow(img)
imgplot.set_cmap('gray')
plt.show()
# Detect keypoints
kp = detector.detect(img, None)
print('Image {} has {} detected keypoints'.format(fullnames[indexList[i]],len(kp)))
img2 = img
img2 = cv2.drawKeypoints(img, kp, img2, flags=0)
# Plot labelled figure
imgplot = plt.imshow(img2)
imgplot.set_cmap('gray')
plt.show()
In [130]:
def describeImage(img):
kp, des = detector.detectAndCompute(img, None)
return des
In [132]:
X = np.vstack([describeImage(img) for img in imgList])
In [135]:
X.shape
Out[135]:
In [137]:
Out[137]: